/*
 * @lc app=leetcode.cn id=1572 lang=typescript
 *
 * [1572] 矩阵对角线元素的和
 */

// @lc code=start
function diagonalSum(mat: number[][]): number {
    let sum = 0;
    for (let i = 0; i < mat.length; i++) {
        const element = mat[i][i];
        sum += element;
    }
    for (let i = 0; i < mat.length; i++) {
        const element = mat[i][mat.length - 1 - i];
        sum += element;
    }
    if (mat.length % 2) {
        const mid = Math.floor(mat.length / 2);
        sum -= mat[mid][mid];
    }
    return sum;
}
// @lc code=end
